package com.eric.text;

import java.util.List;

import org.jsoup.nodes.Document;

import com.eric.downloader.BaiduSERPDownloader;
import com.eric.utils.ListUtils;
import com.eric.utils.Reader;
import com.eric.utils.page.ArticleExtractor;

/**
 * Marketing Toolkit主类，各种工具和方法的入口
 * 
 * @author Eric
 *
 */
public class FactoryManager {

	public static void main(String[] args) {

		BaiduSERPDownloader baiduSerp = new BaiduSERPDownloader();

		List<String> list;
		list = baiduSerp.get("离合器").top10Url();

		StringBuilder sb = new StringBuilder();
		for (String url : list) {
			try {
				Document doc = Reader.read2doc(url);
				ArticleExtractor ex = new ArticleExtractor(doc);
				sb.append(ex.extract().replaceAll("\n|\r", "<p>")); // Keep
																	// paragraph
			} catch (Exception e) {

			}

		}

		//
		// Document doc2 =
		// Reader.read2doc("http://car.autohome.com.cn/shuyu/detail_38_39_909.html");
		// ex = new ArticleExtractor(doc2);
		// sb.append(ex.extract());
		//
		// Document doc3 =
		// Reader.read2doc("http://www.baike.com/wiki/abt&prd=button_doc_entry");
		// ex = new ArticleExtractor(doc3);
		// sb.append(ex.extract());

		TextFactory tf = new SimpleTextFactory(sb.toString());
		AbstractTextWorker tw = tf.createTextWorker(WorkerType.ANSJ_SUMMARY.getName());

		int num = sb.length() / 2; // Summarize to the half of all text length

		tw.sumNum(num);
		tw.produce();
		ListUtils.printList(tw.result());

	}

}
